﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace echuCMS
{
    public partial class FormSalesMan_CustomerDetail : Form
    {
        BindingSource bsSalesMan = new BindingSource();
        public FormSalesMan_CustomerDetail()
        {
            InitializeComponent();
        }

        private void FormSalesMan_CustomerDetail_Load(object sender, EventArgs e)
        {
            dataGridViewSalesMan.AutoGenerateColumns = false;
            dataGridViewCustomerDetail.AutoGenerateColumns = false;
            //查询所有业务员
            bsSalesMan.DataSource = getAllSalesMan();
            this.dataGridViewSalesMan.DataSource = bsSalesMan;
        }

        private List<SalesMan> getAllSalesMan()
        {
            return SalesManService.getAllSalesMan();
        }

        private void dataGridViewSalesMan_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //查看业务员分配的客户
            if (e.RowIndex > -1 && dataGridViewSalesMan.Columns[e.ColumnIndex].Name == "C查看")
            {
                SalesMan salesMan = bsSalesMan.Current as SalesMan;
                List<CustomerMain> customerMains = CustomerMainService.getAllCustomerMainNotInPotentialAndBlack(salesMan.Id);
                BindingSource bs = new BindingSource();
                bs.DataSource = customerMains;
                dataGridViewCustomerDetail.DataSource = bs;
            }
        }
    }
}
